package com.yuanqiao.interfaceforlc.uploadmatterandfile.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class testWord {
    public static void main(String[] args) throws Exception {
        //需要进行文本替换的信息
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("${date}", "2018-03-06");
        data.put("${name}", "东方明珠");
        data.put("${address}", "华东院");
        data.put("${communityvalue}", "");
        data.put("${safetycode}", "华东院");
        data.put("${picture2}", "");
        data.put("${picture3}", "");
        data.put("${buildingvalue2}", "华东院");
        data.put("${patrolPhoto1}", "");
        data.put("${patrolPhoto2}", "");
        data.put("${buildingvalue3}", "中国");

        //图片，如果是多个图片，就新建多个map
        Map<String,Object> picture1 = new HashMap<String, Object>();
        picture1.put("width", 200);
        picture1.put("height", 250);
        picture1.put("type", "jpg");
        picture1.put("content", WorderToNewWordUtils.inputStream2ByteArray(new FileInputStream("D:/testWord/timg.jpg"), true));
        data.put("${picture1}",picture1);

        //需要进行动态生成的信息
        List<Object> mapList = new ArrayList<Object>();

        //第一个动态生成的数据列表
        List<String[]> list01 = new ArrayList<String[]>();
        list01.add(new String[]{"A","11111111111","22","22"});
        list01.add(new String[]{"A","22222222222","33","22"});
        list01.add(new String[]{"B","33333333333","44","22"});
        list01.add(new String[]{"C","44444444444","55","22"});

        //第二个动态生成的数据列表
        List<String[]> list02 = new ArrayList<String[]>();
        list02.add(new String[]{"A","11111111111","22","22"});
        list02.add(new String[]{"d","22222222222","33","22"});
        list02.add(new String[]{"B","33333333333","44","22"});
        list02.add(new String[]{"C","44444444444","55","22"});

        mapList.add(list01);
        mapList.add(list02);

        //需要动态改变表格的位置；第一个表格的位置为0
        int[] placeList = {1,4};

        CustomXWPFDocument doc = WorderToNewWordUtils.changWord("D:/1126xmgl/DM/src/main/resources/model/申请书/合伙企业登记（备案）申请书.docx",data,mapList,placeList);
        FileOutputStream fopts = new FileOutputStream("D:/testWord/testmake.docx");
        doc.write(fopts);
        fopts.close();
    }
}
